
<%@ page import="java.util.List" %>
<%@ page import="com.hyy.bean.Cart" %>
<%@ page import="java.util.Map" %>
<%@ page import="com.hyy.bean.Merchandise" %><%--
  Created by IntelliJ IDEA.
  User: Administrator
  Date: 2020/11/16 0016
  Time: 14:25
  To change this template use File | Settings | File Templates.
--%>
<%@ page contentType="text/html;charset=UTF-8" language="java" %>
<html>
<head>
    <meta charset="UTF-8">
    <title>我的购物车</title>

	<!-- 新 Bootstrap 核心 CSS 文件 -->
	<script src="https://cdn.staticfile.org/jquery/1.10.2/jquery.min.js"></script>
	<!-- 最新版本的 Bootstrap 核心 CSS 文件 -->
	<link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/bootstrap@3.3.7/dist/css/bootstrap.min.css" integrity="sha384-BVYiiSIFeK1dGmJRAkycuHAHRg32OmUcww7on3RYdg4Va+PmSTsz/K68vbdEjh4u" crossorigin="anonymous">
	<!-- 可选的 Bootstrap 主题文件（一般不用引入） -->
	<link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/bootstrap@3.3.7/dist/css/bootstrap-theme.min.css" integrity="sha384-rHyoN1iRsVXV4nD0JutlnGaslCJuC7uwjduW9SVrLvRYooPp2bWYgmgJQIXwl/Sp" crossorigin="anonymous">
	<!-- 最新的 Bootstrap 核心 JavaScript 文件 -->
	<script src="https://cdn.jsdelivr.net/npm/bootstrap@3.3.7/dist/js/bootstrap.min.js" integrity="sha384-Tc5IQib027qvyjSMfHjOMaLkfuWVxZxUPnCJA7l2mCWNIpG9mGCD8wGNIcPD7Txa" crossorigin="anonymous"></script>
	<link rel="stylesheet" href="../css/cart.css" />
	<script type="text/javascript" src="../js/cart.js"></script>
</head>

<body>
<div class="row">
    <!--表头的开始-->
    <div class="col-md-8 col-md-offset-2">
        <div class="row text-valign">
            <div class="col-md-2">
                <h3>我的购物车</h3></div>
            <div class="col-md-9" style="margin-top: 5px"> 温馨提示：产品是否购买成功，以最终下单为准哦，请尽快结算</div>
			<div class="col-md-1">
				<a href="/" style="font-size: 14px;color: #222222">
					<span class="glyphicon glyphicon-home" aria-hidden="true"></span>返回商城
				</a>
			</div>
        </div>
        <!--表头的结束-->
        <table class="table table-bordered">
            <tr>
                <th> </th>
                <th>商品名称</th>
                <th>单价</th>
                <th>数量</th>
                <th>小计</th>
                <th>操作</th>
            </tr>
            <!--jquery实现-->
            <% Map<Merchandise,Long> cartMerchandises = (Map<Merchandise,Long>)request.getAttribute("cartMerchandises"); %>
			<% request.getSession().setAttribute("cartMerchandises",cartMerchandises); %>
            <% double account = 0;%>
            <%for(Map.Entry<Merchandise,Long> entry:cartMerchandises.entrySet()){%>
                <tr>
					<input type="hidden" id="mid" name="mid" value="<%=entry.getKey().getId()%>">
					<th width="250px">
						<img src="img/<%=entry.getKey().getImg()%>" style="width: 100%">
					</th>
                    <th style="display: table-cell;vertical-align:middle;width: 300px"><%=entry.getKey().getProductName()%></th>
                    <th style="display: table-cell;vertical-align:middle;">￥<%=entry.getKey().getPrice()%></th>
                    <th style="display: table-cell;vertical-align:middle;width: 150px">
                        <div class="input-group">
                            <span class="input-group-addon subOne">-</span>
                            <input type="text" class="form-control" value="<%=entry.getValue()%>"
								   id="num<%=entry.getKey().getId()%>"  >
                            <span class="input-group-addon addOne" id="addone">+</span>
                        </div>
                    </th>
                    <th class="smallPrice"
						style="display: table-cell;vertical-align:middle;width: 200px">￥<%=entry.getKey().getPrice()*entry.getValue()%></th>

					<th style="display: table-cell;vertical-align:middle;width: 100px">
						<button type="button" class="btn btn-default"
								onclick="window.location.href='/deleteMyCart?mid=<%=entry.getKey().getId()%>'
										">删除
						</button>
					</th>
                </tr>
                <% account=account+entry.getKey().getPrice()*entry.getValue(); %>
           <%}%>
            <tr>
                <th colspan="6" style="text-align:right">
                    总计：<span id="allPrice" style="font-size: 24px;color: #c9302c">
					￥<%=account%></span>
					<%request.getSession().setAttribute("allPrice",account);%>
                    <input type="submit" value="立即结算" class="btn2"
						   onclick="window.location.href='/toOrder'" />
                </th>
            </tr>
        </table>
    </div>
</div>
</body>

</html>